GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( cc0130...b571b0 )
by Benjamin
01:46
created

editor.js ➔ ???   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 9
Bugs 0 Features 9
Metric Value
cc 4
c 9
b 0
f 9
nc 4
dl 0
loc 47
rs 8.6845
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A editor.js ➔ ... ➔ ??? 0 14 2
1
import { fromJS, Map } from 'immutable';
2
3
import { Editor } from './../../../records';
4
import { generateLastUpdate } from './../../../util/lastUpdate';
5
6
import {
7
    getData,
8
    setDataAtDataIndex,
9
    setKeysInData
10
} from './../../../util/getData';
11
12
export const editRow = (state, {
13
    columns, editMode, rowIndex, rowId, stateKey, top, isCreate, values
14
}) => {
15
16
    if (!values.toJS) {
17
        values = fromJS(values);
18
    }
19
20
    const isValid = isRowValid(columns, values);
21
22
    let overrides = state.getIn([stateKey, rowId, 'overrides'])
23
       ? state.getIn([stateKey, rowId, 'overrides'])
24
       : new Map();
25
26
    columns.forEach((col, i) => {
27
        const val = getData(values, columns, i);
28
        const dataIndex = col.dataIndex;
29
30
        // setting disabled
31
        if (!overrides.get(dataIndex)) {
32
            overrides = overrides.set(dataIndex, new Map());
33
        }
34
35
        overrides = overrides.setIn(
36
            [dataIndex, 'disabled'],
37
            setDisabled(col, val, values)
38
        );
39
    });
40
41
    const operation = editMode === 'inline'
42
       ? 'setIn'
43
       : 'mergeIn';
44
45
    return state[operation]([stateKey], fromJS({
46
        [rowId]: new Editor({
47
            key: rowId,
48
            values: fromJS(values),
49
            rowIndex,
50
            top,
51
            valid: isValid,
52
            isCreate: isCreate || false,
53
            overrides: overrides
54
        }),
55
        lastUpdate: generateLastUpdate()
56
    }));
57
58
};
59
60
export const setData = (state, { data, editMode, stateKey }) => {
61
    if (editMode === 'grid') {
62
63
        const keyedData = setKeysInData(data);
64
        const editorData = keyedData.reduce((prev, curr, i) => {
65
            return prev.set(curr.get('_key'), new Editor({
66
                key: curr.get('_key'),
67
                values: curr,
68
                rowIndex: i,
69
                top: null,
70
                valid: null,
71
                isCreate: false,
72
                overrides: Map()
73
            }));
74
        }, Map({ lastUpdate: generateLastUpdate() }));
75
76
        return state.mergeIn([stateKey], editorData);
77
    }
78
79
    return state;
80
};
81
82
export const rowValueChange = (state, {
83
    column, columns, value, rowId, stateKey
84
}) => {
85
86
    const previousEditorState = state.getIn([stateKey, rowId]);
87
    const previousValues = previousEditorState
88
        ? previousEditorState.values
89
        : new Map();
90
91
    let overrides = previousEditorState
92
        ? previousEditorState.overrides
93
        : new Map();
94
95
    let rowValues = setDataAtDataIndex(
96
        previousValues, column.dataIndex, value
97
    );
98
99
    columns.forEach((col, i) => {
100
        const val = getData(rowValues, columns, i);
101
        const dataIndex = col.dataIndex;
102
103
        // interpreting `change func` to set final values
104
        // happens first, due to other validation
105
        // need to turn back to immutable, since data is
106
        // being retrieved externally
107
        rowValues = fromJS(handleChangeFunc(col, rowValues));
108
109
        // setting default value
110
        if (col.defaultValue !== undefined
111
            && val === undefined || val === null) {
112
            setDataAtDataIndex(rowValues, dataIndex, col.defaultValue);
113
        }
114
115
        // setting disabled
116
        if (!overrides || !overrides.get) {
117
            overrides = new Map();
118
        }
119
120
        if (!overrides.get(dataIndex)) {
121
            overrides = overrides.set(dataIndex, Map());
122
        }
123
124
        overrides = overrides.setIn(
125
            [dataIndex, 'disabled'], setDisabled(col, val, rowValues)
126
        );
127
    });
128
129
    const valid = isRowValid(columns, rowValues);
130
131
    const record = state.getIn([stateKey, rowId]) || new Editor();
132
    const updated = record.merge({
133
        values: rowValues,
134
        previousValues: record.values,
135
        valid,
136
        overrides
137
    });
138
139
    state = state.setIn([stateKey, rowId], updated);
140
141
    return state.setIn(
142
        [stateKey, 'lastUpdate'],
143
        generateLastUpdate()
144
    );
145
};
146
147
export const repositionEditor = (state, { rowId, stateKey, top }) => {
148
    const record = state.getIn([stateKey, rowId]);
149
    const updated = record.merge({ top });
150
    const newState = state.mergeIn([stateKey, rowId], updated);
151
152
    return newState.mergeIn(
153
        [stateKey],
154
        { lastUpdate: generateLastUpdate() }
155
    );
156
};
157
158
export const removeEditorState = (state, { stateKey }) => state.setIn(
159
        [stateKey],
160
        fromJS({ lastUpdate: generateLastUpdate() }));
161
162
// helpers
163
export const isCellValid = ({ validator }, value, values) => {
164
    if (!validator || !typeof validator === 'function') {
165
        return true;
166
    }
167
168
    const vals = values && values.toJS
169
        ? values.toJS()
170
        : values;
171
172
    return validator({ value, values: vals });
173
};
174
175
export const isRowValid = (columns, rowValues) => {
176
    for (let i = 0; i < columns.length; i++) {
177
178
        const col = columns[i];
179
        const val = isCellValid(col, getData(rowValues, columns, i), rowValues);
180
181
        if (!val) {
182
            return false;
183
        }
184
    }
185
186
    return true;
187
};
188
189
export const setDisabled = (col = {}, value, values) => {
190
191
    if (col.disabled === true || col.disabled === 'false') {
192
        return col.disabled;
193
    }
194
195
    if (typeof col.disabled === 'function') {
196
197
        const vals = values && values.toJS
198
            ? values.toJS()
199
            : values;
200
201
        return col.disabled({
202
            column: col,
203
            value,
204
            values: vals
205
        });
206
    }
207
208
    return false;
209
210
};
211
212
export const handleChangeFunc = (col, rowValues) => {
213
214
    const vals = rowValues
215
        && rowValues.toJS
216
        ? rowValues.toJS()
217
        : rowValues;
218
219
    if (!col.change || !typeof col.change === 'function') {
220
        return vals;
221
    }
222
223
    const overrideValue = col.change({ values: vals }) || {};
224
225
    Object.keys(overrideValue).forEach(k => {
226
        vals[k] = overrideValue[k];
227
    });
228
229
    return vals;
230
};
231